package org.weixin4j.pay;

import com.nervenets.utils.JodaUtils;

import java.util.HashMap;
import java.util.Map;

public class WAPay {
    private String appid;
    private String noncestr;
    private String packages;
    private String partnerid;
    private String prepayid;
    private int timestamp;
    private String sign;

    public WAPay(String appId, String partnerId, String prepay_id, String paternerKey) {
        this.appid = appId;
        this.timestamp = JodaUtils.getTimestamp();
        this.partnerid = partnerId;
        this.prepayid = prepay_id;
        this.noncestr = java.util.UUID.randomUUID().toString().substring(0, 15);
        this.packages = "Sign=WXPay";

        //对提交的参数进行签名
        Map<String, String> paySignMap = new HashMap<String, String>();
        paySignMap.put("appid", this.appid);
        paySignMap.put("noncestr", this.noncestr);
        paySignMap.put("partnerid", this.partnerid);
        paySignMap.put("package", this.packages);
        paySignMap.put("prepayid", this.prepayid);
        paySignMap.put("timestamp", String.valueOf(this.timestamp));

        //签名
        this.sign = SignUtil.getSign(paySignMap, paternerKey);
    }

    public Map toMap() {
        Map map = new HashMap();
        map.put("appid", this.appid);
        map.put("noncestr", this.noncestr);
        map.put("partnerid", this.partnerid);
        map.put("package", this.packages);
        map.put("prepayid", this.prepayid);
        map.put("timestamp", this.timestamp);
        map.put("sign", this.sign);
        return map;
    }

    public String getAppid() {
        return appid;
    }

    public void setAppid(String appid) {
        this.appid = appid;
    }

    public String getNoncestr() {
        return noncestr;
    }

    public void setNoncestr(String noncestr) {
        this.noncestr = noncestr;
    }

    public String getPackages() {
        return packages;
    }

    public void setPackages(String packages) {
        this.packages = packages;
    }

    public String getPartnerid() {
        return partnerid;
    }

    public void setPartnerid(String partnerid) {
        this.partnerid = partnerid;
    }

    public String getPrepayid() {
        return prepayid;
    }

    public void setPrepayid(String prepayid) {
        this.prepayid = prepayid;
    }

    public int getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(int timestamp) {
        this.timestamp = timestamp;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }
}
